Color Spaces
A color space specifies how color information is represented. It defines a one-, two-, three-, or four-dimensional space whose dimensions, or components, represent intensity values. For example, RGB space is a three-dimensional color space whose components are the red, green, and blue intensities that make up a given color. Visually, these spaces are often represented by various solid shapes, such as cubes, cones, or polyhedra. See, for example, Color Plate 4 at the front of this book.QuickDraw GX directly supports 28 different color spaces, to give you the convenience of working in whatever kinds of color data most suits your needs. The QuickDraw GX color spaces fall into several groups, or base families. They are
All color spaces within a base family differ only in details of storage format or else are related to each other by very simple mathematical formulas. Conversion of color across base families is more complex, as described in the section "Color Conversion and Color Matching" beginning on page 4-26.
- luminance-based color spaces, used for grayscale display and printing
- RGB-based color spaces, used mainly for color video display
- CMYK-based color spaces, used mainly for color printing
- universal color spaces, used mainly for device-independent color measurements
Within a base family, some of the differences among color spaces relate to their packing, the number of bits used to store each color component. For example, RGB colors might be stored with 5, 8, or 16 bits per component. Each storage format is a different color space. Internally, QuickDraw GX always converts colors so that each component has 16 bits; thus you can think of the 16-bit-per-component color spaces as the fundamental ones in each base family, and those with smaller storage spaces as packed (storage-compressed) versions.
Some QuickDraw GX color spaces have an alpha channel, an additional component that measures opacity or transparency. Alpha channels are described in the section "Color Spaces With Alpha Channels" beginning on page 4-24.
QuickDraw GX also supports a derived color space--indexed color space--in which colors are indirectly specified, using values that are indexed positions in a list. The colors in that list, however, must still belong to one of the base-family color spaces.
The
gxColorSpaces
enumeration, shown on page 4-55, lists the color spaces directly supported by QuickDraw GX. Each color space has its own format for representing color information. The rest of this section discusses those color spaces and their formats.Luminance-Based Color Spaces
Luminance is a scale of lightness. Luminance-based color spaces, or gray spaces, typically have a single component, ranging from black to white, as shown in Figure 4-1. Luminance-based color spaces are used for black-and white and grayscale display and printing.Figure 4-1 Luminance color space
A color is converted into luminance by evaluating its overall lightness. The luminance of a color expressed in RGB (see "RGB-Based Color Spaces" beginning on page 4-9), for example, can be calculated approximately with this formula:
luminance = 0.30 * red + 0.59 * green + 0.11 * blue;(QuickDraw GX provides a function for converting colors among different color spaces.)The luminance-based color spaces supported by QuickDraw GX (and defined in the
gxColorSpaces
enumeration) aregxGraySpace
andgxGrayASpace
. The A ingxGrayASpace
stands for a second component called an alpha channel; see the section "Color Spaces With Alpha Channels" beginning on page 4-24 for more information.Table 4-1 describes details of the storage formats for
gxGraySpace
andgxGrayASpace
. In each of these spaces, the luminance is specified by a single
number whose range varies from 0 to 65,535. The color black has a luminance value
of 0, regardless of the color space.
Table 4-1 Luminance-based color spaces supported by QuickDraw GX Constant Enumeration
ValueExplanation gxGraySpace 0x000A 16 bits per component (gray only); component values range from 0 to 0xFFFF. Total storage size for each color value: 16 bits. gxGrayASpace 0x008A 16 bits per component (gray and alpha); component values range from 0 to 0xFFFF. Total storage size for each color value: 32 bits. Alpha channels are described on page 4-24.
Figure 4-2 is a visual representation of the storage formats for the luminance-based color spaces.
Figure 4-2 Storage formats for luminance-based color spaces
- Note
- This figure and all subsequent storage-format figures in this chapter assume that data storage is "big-endian," that is, that lower addresses correspond to higher-order bytes in a word or long word value. For processors whose storage model is different, the elements of the figures would be in a different order. These figures are presented for illustrative purposes only, and are not intended to specify details of storage order.
![]()
QuickDraw GX does not support an 8-bit luminance-based color space because such a color space can be more conveniently represented as an indexed color space with a color set. Indexed color space is described in the section "Indexed Color Spaces" beginning on page 4-22; color sets are described in the section "When Color Matching Occurs" beginning on page 4-31.
RGB-Based Color Spaces
RGB-based color spaces are the most commonly used color spaces in computer graphics, primarily because they are directly supported by most color monitors. The groups of color spaces within the RGB base family include
- RGB spaces
- HSV and HLS spaces
RGB Spaces
Any color expressed in RGB space is some mixture of three primary colors red, green, and blue. Most RGB-based color spaces can be visualized as a cube, as in Figure 4-3, with corners of black, the three primaries (red, green, and blue), the three secondaries (cyan, magenta, and yellow), and white. See, for example, Figure 4-3; see also Color Plate 4 at the front of this book.
The RGB color spaces supported by QuickDraw GX (and defined in the
gxColorSpaces
enumeration) aregxRGBSpace
,gxRGB16Space
,gxRGB32Space
,gxRGBASpace
, andgxARGB32Space
. See Table 4-2 and Figure 4-4 for storage-format details. In each of these spaces, a color value is represented by three or four color components, representing red, green, blue (and in some cases alpha); each component can vary in the number of bits used for its storage. The color black is represented by component values of 0 in the red, green, and blue components.
Table 4-2 RGB color spaces supported by QuickDraw GX Constant Enumeration
ValueExplanation gxRGBSpace 0x0001 16 bits per component (red, green, and blue); component values range from 0 to 0xFFFF.
Total storage size for each color value: 48 bits.gxRGB16Space 0x0501 5 bits per component (red, green, and blue); component values range from 0 to 0x1F. Total storage size for each color value: 16 bits (bit 15
is not used).gxRGB32Space 0x0801 8 bits per component (red, green, and blue); component values range from 0 to 0xFF. Total storage size for each color value: 32 bits
(bits 24-31 are not used).gxARGB32Space 0x1881 8 bits per component (red, green, blue, and alpha); component values range from 0 to 0xFF. Total storage size for each color value: 32 bits. Alpha channels are described on page 4-24. gxRGBASpace 0x0081 16 bits per component (red, green, blue, and alpha); component values range from 0 to 0xFFFF. Total storage size for each color value:
64 bits. Alpha channels are described on page 4-24.Figure 4-4 Storage formats for RGB color spaces
HSV and HLS Color Spaces
HSV space and HLS space are transformations of RGB space that allow colors to be described in terms more natural to an artist. The name HSV stands for hue, saturation, and value, and HLS stands for hue, lightness, and saturation. The two spaces can be thought of as being single and double cones, as shown in Figure 4-5. (See also Color Plate 4 at the front of this book for a slightly different representation of these color spaces.)Figure 4-5 HSV color space and HLS color space
The components in HLS space are analogous, but not completely identical, to the components in HSV space:
The HLS and HSV color spaces supported by QuickDraw GX (and defined in the
- The hue component in both color spaces is an angular measurement, analogous to position around a color wheel. A hue value of 0 indicates the color red; the color green is at a value corresponding to 120, and the color blue is at a value corresponding to 240. Horizontal planes through the cones in Figure 4-5 are hexagons; the primaries and secondaries (red, yellow, green, cyan, blue, and magenta) occur at the vertices of the hexagons.
- The saturation component in both color spaces describes color intensity. A saturation value of 0 (in the middle of a hexagon) means that the color is "colorless" (gray); a saturation value at the maximum (at the outer edge of a hexagon) means that the color is at maximum "colorfulness" for that hue angle and brightness.
- The value component (in HSV space) and the lightness component (in HLS space) describe brightness or luminance. In both color spaces, a value of 0 represents black. In HSV space, a maximum value for value means that the color is at its brightest. In HLS space, a maximum value for lightness means that the color is white, regardless of the current values of the hue and saturation components. The brightest, most intense color in HLS space occurs at a lightness value of exactly half the maximum.
gxColorSpaces
enumeration) aregxHSVSpace
,gxHLSSpace
,gxHSV32Space
,
andgxHLS32Space
. See Table 4-3 and Figure 4-6 for details of storage format.Figure 4-6 shows storage formats for the supported HSV color spaces. Formats for the HLS spaces are identical.
Figure 4-6 Storage formats for HSV color spaces
CMYK Color Spaces
CMYK space is a color space that models the way ink builds up in printing. The name CMYK refers to cyan, magenta, yellow, and black. Cyan, magenta, and yellow are the three primary colors in this color space, and red, green, and blue are the three secondaries. Theoretically black is not needed. However, when full-saturation cyan, magenta, and yellow inks are mixed equally on paper, the result is usually a dark brown, rather than black. Therefore, black ink is overprinted in darker areas to give a better appearance. Figure 4-7 shows how the primary colors in CMYK space mix to form other colors. (See also Color Plate 4 at the front of this book.)Figure 4-7 Colors in CMYK color space
Theoretically, the relation between RGB values and CMY values in CMYK space is quite simple:
Cyan = 1.0 - red; Magenta = 1.0 - green; Yellow = 1.0 - blue;(where red, green, and blue intensities are expressed as fractional values varying from 0 to 1). In reality, the process of deriving the cyan, magenta, yellow, and black values from a color expressed in RGB space is complex, involving device-specific, ink-specific, and even paper-specific calculations of the amount of black to add in dark areas (black generation), and the amount of other ink to remove (undercolor removal) where black is to be printed. QuickDraw GX performs those calculations for you when converting among color spaces, commonly using color profiles as described in the section "Color Profiles" beginning on page 4-28.The CMYK color spaces supported by QuickDraw GX (and defined in the
gxColorSpaces
enumeration) aregxCMYKSpace
and gxCMYK32Space. See
Table 4-4 and Figure 4-8 for details of storage format.Figure 4-8 Storage formats for CMYK color spaces
Universal Color Spaces
Some color spaces allow color to be expressed in a device-independent way. Whereas RGB colors vary with monitor characteristics, and CMYK colors vary with printer and paper characteristics, universal colors are meant to be true representations of colors as perceived by the human eye. These color representations, called universal color spaces, result from work carried out in 1931 by the Commission Internationale d'Eclairage (CIE), and for that reason are also called CIE-based color spaces.In addition, broadcast-video color space (YIQ) is based on device-independent color characteristics, in that its colors are measured in terms of a standard device. It is therefore considered universal and is discussed in this section.
XYZ Space
There are several CIE-based color spaces, but all are derived from the fundamental XYZ space. The XYZ space allows colors to be expressed as a mixture of the three tristimulus values X, Y, and Z. The term tristimulus comes from the fact that color perception results from the retina of the eye responding to three types of stimuli. After experimentation, the CIE set up a hypothetical set of primaries, XYZ, that correspond to the way the eye's retina behaves.The CIE defined the primaries so that all visible light maps into a positive mixture of X, Y, and Z, and so that Y correlates approximately to the apparent lightness of a color. Generally, the mixtures of X, Y, and Z components used to describe a color are expressed as percentages ranging from 0% up to, in some cases, just over 100%.
Other universal color spaces based on XYZ space are used primarily to relate some particular aspect of color or some perceptual color difference to XYZ values.
Yxy Space
Yxy space expresses the XYZ values in terms of x and y chromaticity coordinates, somewhat analogous to the hue and saturation coordinates of HSV space. The coordinates are shown in the following formulas, used to convert XYZ into Yxy:
Y = Y x = X / (X+Y+Z) y = Y / (X+Y+Z)Note that the Z tristimulus value is incorporated into the new coordinates, and does not appear by itself. Since Y still correlates to the lightness of a color, the other aspects of the color are found in the chromaticity coordinates x and y. This allows color variation in Yxy space to be plotted on a two-dimensional diagram. Figure 4-9 shows the layout of colors in the x and y plane of Yxy space. Color Plate 4 at the front of this book shows the same plot in color.
L*u*v* Space and L*a*b* Space
One problem with representing colors using the XYZ and Yxy color spaces is that they are perceptually nonlinear: it is not possible to accurately evaluate the perceptual closeness of colors based on their relative positions in XYZ or Yxy space. Colors that are close together in Yxy space may seem very different to observers, and colors that seem very similar to observers may be widely separated in Yxy space.L*u*v* space is a nonlinear transformation of XYZ space in order to create a perceptually linear color space. L*a*b* space is a nonlinear transformation (a third-order approximation) of the Munsell color-notation system (not described here). Both are designed to match perceived color difference with quantitative distance in color space.
Both L*u*v* space and L*a*b* space represent colors relative to a reference white point, which is a specific definition of what is considered white light, represented in terms of XYZ space, and usually based on the whitest light that can be generated by a given device. (In that sense L*u*v* and L*a*b* are not completely device independent; two numerically equal colors are truly identical only if they were measured relative to the same white point.)
Measuring colors in relation to a white point allows for color measurement under a variety of illuminations. The luminance of the white point of the QuickDraw GX default color profile matches the luminance of the white point on the Apple 13-inch color monitor. Color profiles are described in the section "Color Conversion and Color Matching" beginning on page 4-26.
A primary benefit of using L*u*v* space and L*a*b* space is that the perceived
difference between any two colors is proportional to the geometric distance in the color space between their color values. For applications where closeness of color needs to be quantified, such as in colorimetry, gemstone evaluation, or dye matching, use of L*u*v* space or L*a*b* space is common.The formulas for transforming an XYZ color into an L*u*v* color are
if (Y/Yn > 0.008856) L = 116.0 * (Y / Yn)1/3 - 16.0; else L = 903.3 * (Y / Yn); u = 13.0 * L * (u' - u'n); v = 13.0 * L * (v' - v'n);where
u' = 4 * x / (X + 15*Y + 3*Z); v' = 9 * y / (X + 15*Y + 3*Z);andu'n
,v'n
, andYn
are theu'
,v'
, andY
values for the reference white point.Similarly, the formulas for transforming an XYZ color into an L*a*b* color are
if (Y/Yn > 0.008856) L = 116.0 * (Y / Yn)1/3 - 16.0; else L = 903.3 * (Y / Yn) a = 500.0 * ( (X / Xn)1/3 - (Y / Yn)1/3 ); b = 500.0 * ( (Y / Yn)1/3 - (Z / Zn)1/3 );whereXn
,Yn
, andZn
are the XYZ values for the reference white point.Formats for XYZ-Based Color Spaces
The universal color spaces supported by QuickDraw GX (and defined in thegxColorSpaces
enumeration) aregxYXYSpace
,gxXYZSpace
,gxLUVSpace
,gxLABSpace
,gxYXY32Space
,gxXYZ32Space
,gxLUV32Space
, andgxLAB32Space
. See Table 4-5 and Figure 4-10 for details of storage format. Note that the ranges of values for the components differ significantly among the different color spaces.Figure 4-10 shows storage formats for the supported XYZ color spaces. Formats for the Yxy, L*u*v*, and L*a*b* spaces are identical.
Figure 4-10 Storage formats for XYZ color spaces
Video Color Spaces
YIQ space is sometimes called video color space. It is based on the way a specific kind of RGB data is broken down for color television transmission. The three dimensions that describe these color spaces are Y, I, and Q, in which Y represents luminance and the other two components carry color information.Because the Y channel represents luminance it can be used alone; the Y channel is the only channel used in black and white television. The I and Q channels are called color difference channels: the Y channel is split between them. The notations "I" and "Q" stand for "in phase" and "in quadrature," respectively, referring to the method by which all of the channels are combined into a signal for broadcast.
QuickDraw GX also defines NTSC and PAL color spaces. NTSC space corresponds to the color encoding used for color broadcasting in the United States, whereas PAL space corresponds to the color encoding used in Europe. NTSC and PAL have different screen resolutions, frequencies, and are otherwise incompatible, but in terms of how color values are calculated, NTSC space and PAL space are both identical to YIQ space.
In YIQ space, the Y component can vary from 0 (black) to its maximum value (full luminance). I and Q are normally signed values, so they are centered around 0.
Figure 4-11 illustrates how colors map into the I and Q dimensions of YIQ space.Figure 4-11 The I and Q axes in YIQ color space
The video color spaces supported by QuickDraw GX (and defined in the
gxColorSpaces
enumeration) aregxYIQSpace
,gxNTSCSpace
,gxPALSpace
,gxYIQ32Space
,gxNTSC32Space
, andgxPAL32Space
. See Table 4-6 and
Figure 4-12 for details of storage format. In each of these spaces, a color value is represented by Y, I, and Q color components.Figure 4-12 shows storage formats for the supported YIQ color spaces. Formats for the NTSC and PAL spaces are identical.
Figure 4-12 Storage formats for YIQ color spaces
You can find more information on the theories of color and the various color spaces in the following publications:
Measuring Color, by R.W.G. Hunt, John Wiley & Sons, New York, 1987.
Illumination and Color in Computer Generated Imagery, by Roy Hall, Springer-Verlag, New York, 1989.
Indexed Color Spaces
In situations where you use only a limited number of colors, it can be impractical or impossible to specify colors directly. For example, if you have a bitmap with only a few bits per pixel (1, 2, 4 or 8 for QuickDraw GX), each pixel is too small to contain a complete color specification; its color must be specified as an index into a list or table of color values. If you are using spot colors in printing or pen colors in plotting, it can be simpler and more precise to specify each color as an index into a list instead of an actual color value. Also, if you want to restrict the user to drawing with a specific set of colors, you can put them in a list and specify them by index.Indexed space is the color space you use when drawing with indirectly specified colors. An indexed color value (a color specification in indexed color space) consists of an index value and a reference to a color set object. The color set contains a list of color values and a specification of the color space for those color values; the index value specifies which color to use from the list. Color values are defined in the section "Color-Component Values, Color Values, and Colors" beginning on page 4-25. Color set objects are described in the section "About Color Set Objects" beginning on page 4-32.
QuickDraw GX supports the single indexed color space format
gxIndexedSpace
(defined in thegxColorSpaces
enumeration). See Table 4-7 and Figure 4-4 for details of storage format. Although there is a single format for indexed color space, you can create any number of unique indexed color spaces, using different sets of colors from any of the defined color spaces.Figure 4-13 Storage format for indexed color space
- Color spaces and bitmaps
- Bitmaps commonly use indexed color space, but if pixel size is large enough a bitmap can specify colors directly in any color space. These are the restrictions on the use of color spaces with bitmaps:
![]()
- Bitmaps with 1, 2, 4, or 8 bits per pixel must use
gxIndexedSpace
.- Bitmaps with 16 bits per pixel can use
gxRGB16Space
. They cannot usegxIndexedSpace
.- Bitmaps with 32 bits per pixel can use
gxRGB32Space
,gxARGB32Space
,gxCMYK32Space
,gxHSV32Space
,gxHLS32Space
,gxYXY32Space
,gxXYZ32Space
,gxLUV32Space
,gxLAB32Space
,gxYIQ32Space
,gxNTSC32Space
, orgxPAL32Space
--that is, all defined 32-bit color spaces.
They cannot usegxIndexedSpace
.- Hardware devices that have 24 bits of physical memory per pixel can support
gxRGB32Space
. Hardware devices that have 32 bits of physical memory per
pixel can supportgxRGB32Space
plus all the other defined 32-bit color spaces.
Bitmaps are described further in the bitmap shapes chapter of Inside Macintosh: QuickDraw GX Graphics.![]()
Color Spaces With Alpha Channels
QuickDraw GX supports the use of an alpha channel in one luminance-based color space (gxGrayASpace
) and two RGB color spaces (gxRGBASpace
andgxARGB32Space
). An alpha channel is a component in a color space whose value typically determines the opacity of the color expressed by the other components. An alpha-channel value of 0 in a color means that the color is completely transparent, and a maximum value means that the color is completely opaque. A value in between means that the color is partially transparent.How transparency is handled in drawing depends on the transfer mode used when the color is drawn. (Transfer modes are discussed in the chapter "Ink Objects" in this book.) Typically, however, transparency in a color being drawn--the source color-- means that the existing color at the location where drawing occurs--the destination color--shows through. Where the source is completely opaque, the destination is completely covered and is invisible; where the source is completely transparent, the destination shows through unchanged and the source is invisible.
Figure 4-14 shows an example in which a uniform gray image (in
gxGrayASpace
) is drawn over a black-and-white image. The gray color of the source is uniform across the rectangle, but the alpha-channel value decreases from 0xFFFF on the left to 0 on the right. As the alpha value decreases rightward, more and more of the destination color shows through. (Color Plate 2 at the front of this book shows a similar drawing example in color.)Figure 4-14 Showing color transparency with an alpha channel
For more information on using alpha channels to achieve particular drawing effects, see the chapter "Ink Objects" in this book.